using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

namespace produccion.clases
{

   public  class CLSMAEALM : ObservableObject
    {

MDOgeneral mod = new MDOgeneral();

#region Metodos basicos tabla
public List<CLSMAEALM> listaAlmMat()
    {
        try
        {
            string query = "select CODALM_ALM,NOMALM_ALM from MAEALMP Order by NOMALM_ALM";
                DataTable val = mod.consulta(query);
                List<CLSMAEALM> listaMatPri = new List<CLSMAEALM>();
                foreach (DataRow r in val.Rows)
                {
                    listaMatPri.Add(new CLSMAEALM { CODALM_ALM = r["CODALM_ALM"].ToString(), NOMALM_ALM = r["NOMALM_ALM"].ToString() });
                }
                return listaMatPri;
        }
        catch (Exception e) { throw e; }
    }
    public int actualizar()
    {
        try
        {
            string query = "update MAEALMP set NOMALM_ALM='" + NOMALM_ALM + "' where (CODALM_ALM='" + CODALM_ALM + "')";
            return mod.comando(query);
        }
        catch (Exception e) { throw e; }
    }
    public int insertar()
    {
        try
        {
            string query = "insert into MAEALMP (CODALM_ALM,NOMALM_ALM) values ('" + CODALM_ALM + "','" + NOMALM_ALM + "')";
            return mod.comando(query);
        }
        catch (Exception e) { throw e; }
    }
    public void consultar() 
    {
        try
        {
            string query = "select NOMALM_ALM from MAEALMP where CODALM_ALM='" + CODALM_ALM + "'";
            DataTable val = mod.consulta(query);
            if (val.Rows.Count > 0)
            {
                this.NOMALM_ALM = val.Rows[0]["NOMALM_ALM"].ToString();
                EXISTE = true;
                CAMBIO = false;
            }
            else
            {
                 EXISTE = false;
            }
            
        }
        catch (Exception e) { throw e; }
    }
    public int eliminar()
    {
        try
        {
            string query = "delete from MAEALMP where (CODALM_ALM='" + CODALM_ALM + "')";
            return mod.comando(query);
        }
        catch (Exception e) { throw e; }
    }
#endregion

#region  Propiedades tabla MAEALM

    private string _CODALM_ALM;
    public string CODALM_ALM
    {
    get { return _CODALM_ALM; }
    set
    {   _CODALM_ALM = value;
        RaisePropertyChangedEvent("CODALM_ALM");
        }
    }
    private string _NOMALM_ALM;
    public string NOMALM_ALM
    {
        get { return _NOMALM_ALM; }
        set {
            if (_NOMALM_ALM != value) { CAMBIO = true; }
            _NOMALM_ALM = value;
            RaisePropertyChangedEvent("NOMALM_ALM");
        }
    }
    private Boolean _CAMBIO=false;
    public Boolean CAMBIO
    {
        get { return _CAMBIO; }
        set
        {
            _CAMBIO = value;
            RaisePropertyChangedEvent("CAMBIO");
        }
    }
    private Boolean _EXISTE=false;
    public Boolean EXISTE
    {
        get { return _EXISTE; }
        set
        {
            _EXISTE = value;
            RaisePropertyChangedEvent("EXISTE");
        }
    }

#endregion

      }
}
